﻿using System;
using System.Collections.Generic;
using System.Text;

namespace eKanbanWPF.Model
{
    [Serializable]
    public class MemberTask
    {
        public MemberTask()
        {
            Task = null;
            finishTime = DateTime.MaxValue;
            startTime = DateTime.Now.Date;
        }

        public MemberTask(Task task) : this()
        {            
            Task = task;
        }

        public Task Task { get; set; }

        
        private DateTime startTime;
        public DateTime StartTime
        {
            get { return startTime; }
            set
            {
                if (value > FinishTime)
                {
                    throw new ArgumentException("Start Time cannot be larger than Finish Time");
                };
                startTime = value;
            }
        }
        private DateTime finishTime;
        public DateTime FinishTime
        {
            get { return finishTime; }
            set
            {
                if (value < StartTime)
                {
                    throw new ArgumentException("Finish Time cannot be less than Start Time");
                }
                finishTime = value;
            }
        }

        public bool Finished
        {
            get { return FinishTime != DateTime.MaxValue; }
            set
            {
                if (value)
                {
                    FinishTime = DateTime.Now.Date;
                }
                else
                {
                    FinishTime = DateTime.MaxValue;
                }
            }
        }
        public override string ToString()
        {
            string str = Task.ToString();
            str += String.Format("\nStartTime: {0}\tFinishTime: {1}", StartTime, FinishTime);
            return str;
        }
    }
}
